package com.szholly.pro.watergas_server.ps.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.springframework.stereotype.Service;

import com.szholly.pro.watergas_server.common.data.DataUtil;
import com.szholly.data.general.GlobalParameter;
import com.szholly.data.general.RowBase;

/**
 * 参数service
 * @author Administrator
 *
 */
@Service
public class PollInfoService {

	/**
	 * 根据站点集合获取各个站点的参数集合
	 * @param stationCodes
	 * @return
	 */
	public HashMap<String, List<RowBase>> getMulitStationPolls(String[] stationCodes){
		
		String inWhereStr = lrq.common.StringUtil.getArrayStrForSql(stationCodes, "stationId");
		List<GlobalParameter> pc = DataUtil.arrayToParameters(stationCodes, "stationId");
		
		String sql = "select S_DOMAINCODE code,S_DOMAINCAPTION name,S_UNIT UNIT,ms.code station_code,ms.name station_name from BC_SITE_POLL sp\n" +
						"   left join DATA_DEFULATDOMAIN dd on dd.S_DOMAINCODE = sp.name and dd.s_domainname='MONITOR_PARAM'\n" + 
						"   left join BC_SITE_INFO ms on ms.code = sp.site_id \n" + 
						"  where site_id in "+inWhereStr+" "+ 
						" order by sp.site_id, i_order asc ";

		HashMap<String, List<RowBase>> resultMap = new HashMap<>();		
		List<RowBase> result = DataUtil.getSelectRows(sql, pc);
		HashMap<String, String> UnitMap=new HashMap<>();
		UnitMap.put("011", "mg");
		UnitMap.put("060", "mg");
		UnitMap.put("065", "mg");
		UnitMap.put("015", "mg");
		UnitMap.put("101", "mg");
		UnitMap.put("ss", "mg");
		UnitMap.put("cond", "us");
		UnitMap.put("do", "mg");
		UnitMap.put("029", "mg");
		UnitMap.put("028", "mg");
		Iterator<Entry<String, String>> iter=UnitMap.entrySet().iterator();
		
		for(RowBase row : result){
			
			String stationName = row.getSafeString("STATION_NAME");
			
			while(iter.hasNext()){
				Entry<String, String> entry = iter.next();
				if(row.getSafeString("CODE").equals(entry.getKey()))
				row.setValue("COU_UNIT", entry.getValue());
			}
			if(!resultMap.containsKey(stationName)){
				resultMap.put(stationName, new ArrayList<RowBase>());
			}
			resultMap.get(stationName).add(row);
		}		
		return resultMap;		
	}
	
}
